//
//  MKPopPresentationController.swift
//  101weibo
//
//  Created by 劢克科技 on 2019/1/18.
//  Copyright © 2019 劢克科技. All rights reserved.
//

import UIKit

class MKPopPresentationController: UIPresentationController {
    
    private lazy var cover = UIView()
    var currentFrame = CGRect.zero
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        presentedView?.frame = currentFrame
    
        setCover()
    }
}

//MARK: - UI
extension MKPopPresentationController {
    private func setCover() {
        cover.frame = containerView?.bounds ?? CGRect.zero
        cover.backgroundColor = UIColor.lightGray
        cover.alpha = 0.6
        containerView?.insertSubview(cover, at: 0)
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(hidePop))
        cover.addGestureRecognizer(tap)
    }
}

//MARK: - Event
extension MKPopPresentationController {
    @objc private func hidePop() {
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
